﻿Imports ControleMatricula.Negocio

Public Class FrmListaAluno
    Dim db As New DataClassesDataContext()

    Private Sub FrmListaAluno_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        MontarComboEspecifica(cmbEspecifica)
        cmbEspecifica.SelectedIndex = -1
    End Sub

    Private Sub btnCancela_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancela.Click

        cmbEspecifica.SelectedIndex = -1

    End Sub

    Private Sub btnConfirma_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConfirma.Click

        Dim ListEspecifica As List(Of SPEspecificaConsultarResult)
        ListEspecifica = db.SPEspecificaConsultar(0, Convert.ToString(cmbEspecifica.Text)).ToList()

        Dim ListListaAlunos As List(Of SPListaAlunoResult)
        ListListaAlunos = db.SPListaAluno(ListEspecifica(0).IDEspecifica).ToList()

        Dim DSLista As DataSet
        DSLista = New DataSet()

        DSLista.Tables.Add(New DataTable("SPListaAluno"))

        DSLista.Tables(0).Columns.Add("Nome")
        DSLista.Tables(0).Columns.Add("DEEspecifica")

        If ListListaAlunos.Count > 0 Then

            For x = 0 To ListListaAlunos.Count - 1

                Dim row As DataRow = DSLista.Tables(0).NewRow()

                row("Nome") = ListListaAlunos(x).Nome
                row("DEEspecifica") = ListListaAlunos(x).DEEspecifica

                DSLista.Tables(0).Rows.Add(row)

            Next

        Else

            MsgBox("Não foi encontrado nenhum registro!", MsgBoxStyle.Information)
            Exit Sub

        End If

        DSLista.AcceptChanges()

        Dim DS As New DataSet

        DS.Tables.Add(DSLista.Tables(0).Copy)

        DS.AcceptChanges()

        Dim ListaAlunos As ListaAlunos
        ListaAlunos = New ListaAlunos()

        ListaAlunos.SetDataSource(DS)

        RelListaAlunos.CrystalReportRelListaAlunos.ReportSource = ListaAlunos
        RelListaAlunos.CrystalReportRelListaAlunos.RefreshReport()

        RelListaAlunos.Show()

    End Sub

End Class